package cn.train.service;


import java.math.BigDecimal;
import java.sql.Date;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import cn.train.dao.IQueryTrain;
import cn.train.model.Carpiao;
import cn.train.model.Query;
import cn.train.model.ZuoType;
import cn.train.util.SqlSessionFactoryUtil;

/*
 * 列车查询
 */
public class QueryTrainService {
	SqlSession session=SqlSessionFactoryUtil.getSqlSession();
	IQueryTrain querytrain=session.getMapper(IQueryTrain.class);
	//分页查询
	public int getCount(){
		 return querytrain.getCount();
	 }
	public List<Carpiao> QueryTain(int pageIndex,int pageSize){
		 pageIndex=(pageIndex-1)*pageSize;
		return querytrain.QueryTain( pageIndex,pageSize);

    } 
	//模糊查詢	
	public List<Query> QueryByKeyword(String gname,Date time ,int pageIndex,int pageSize){
		 pageIndex=(pageIndex-1)*pageSize;
		System.out.println("当前是"+pageIndex+"条数"+pageSize);
	return querytrain.QueryByKeyword(gname, time,pageIndex,pageSize);		
	}
	public int getCount1(String goname,Date time){
		return querytrain.getCount1(goname, time);
	}
	//前台查询 单程
	public List<Query>QueryByDanCheng(String goname,String overname,Date gettime){
		System.out.println(goname);
		System.out.println(overname);
		System.out.println(gettime);
		return querytrain.QueryByDanCheng(goname, overname, gettime);
	}
	//根据座位类型查票价
	public List<ZuoType> QueryPrice(){
		return querytrain.QueryPrice();
	}
	
	
	/*增加浏览记录*/
	public Integer addjilu(String goname,String overname,BigDecimal jibenjia){
		Integer jilu= querytrain.lookjilu(goname, overname);
		Integer flag=0;
		
		System.out.println("gfgg===="+jilu);
		
		if(jilu==0){
			flag=querytrain.addjilu(goname, overname, jibenjia);
		}else{
			flag=querytrain.updatejilu(goname, overname);
		}
		if(flag==1){
			session.commit();
		}
		
		return flag;
		
	}
	
	}
